package models

import "github.com/zw2582/ginlib"

//AccountIp 账户可用ip
type AccountIp struct {
	Id int `xorm:"pk autoincr"`
	AccountId int
	Ip string `xorm:"varchar(32) comment('可信任客户端ip')"`
}

func init()  {
	ginlib.XormAddWaitSync(new(AccountIp))
}

func ValidAccountIp(accountId int, ip string) ResultCode {
	cnt,_ := DB.Table(AccountIp{}).Where("account_id=?", accountId).Count()
	if cnt == 0 {
		return nil
	}
	cnt,_ = DB.Table(AccountIp{}).Where("account_id=? and ip=?", accountId, ip).Count()
	if cnt == 0 {
		return RC_NO_IP
	}
	return nil
}